import XLSX from 'xlsx';

export default {
    methods: {
        // 获取Excel文件内容
        writeExcelFile(data, fileName) {
            return new Promise((resolve, reject) => {
                /* original data */
                const ws_name = "SheetJS";
                if(typeof console !== 'undefined') console.log(new Date());
                const wb = XLSX.utils.book_new();
                // const ws = XLSX.utils.aoa_to_sheet(data);
                const ws = XLSX.utils.json_to_sheet(data);
                /* add worksheet to workbook */
                XLSX.utils.book_append_sheet(wb, ws, ws_name);
                /* write workbook */
                if(typeof console !== 'undefined') console.log(new Date());
                XLSX.writeFile(wb, fileName);
                if(typeof console !== 'undefined') console.log(new Date());
                resolve();
            });
        },
    },
}
